package com.baizan.daka.ui.adapter


import android.view.View.GONE
import android.widget.TextView
import com.baizan.daka.mvp.model.bean.VipBean
import com.baizan.daka.ui.activity.PayActivity
import com.baizan.daka.util.HyperTextUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.dianzan.daka.R

class VipHomeAdapter(val type: Int? = 0) :
    BaseQuickAdapter<VipBean, BaseViewHolder>(R.layout.item_vip) {
    var vipLevel: Int? = null

    fun setUserVipLevel(vipLevel: Int?) {
        this.vipLevel = vipLevel
        notifyDataSetChanged()
    }

    override fun convert(helper: BaseViewHolder, item: VipBean) {
        val submit = helper.getView<TextView>(R.id.task_submit_tv)
        submit.text = "去购买"
        helper.setText(R.id.vip_content, item.vipName)
            .setText(
                R.id.vip_money, HyperTextUtil.build(item.unitAmount)
                    .appendSize("元", 12).Builder()
            )
            .setText(R.id.vip_des, item.vipDesc)
        submit.setOnClickListener {
            PayActivity.startPayVip(mContext, item)
        }
        vipLevel?.let {
            if ((it + 1) >= item.vipLevel) {
                helper.setGone(R.id.color, false)
            } else {
                helper.setGone(R.id.color, true)
            }
        } ?: let {
            helper.setGone(R.id.color, false)
        }

        if (type == 1) {
            submit.visibility = GONE
        } else {

        }
        var taskLevel = helper.getView<TextView>(R.id.vip_content)
        when (item.vipLevel) {
            1 -> {
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_1)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_1)
                    , null, null, null
                )
            }
            2 -> {
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_2)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_2)
                    , null, null, null
                )
            }
            3 -> {
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_3)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_3)
                    , null, null, null
                )
            }
            4 -> {
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_4)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_4)
                    , null, null, null
                )
            }
        }
    }

}